//
//  SourceUrlView.m
//  ebook
//
//  Created by mt on 16/7/26.
//  Copyright © 2016年 Moton. All rights reserved.
//

#import "SourceUrlView.h"

@implementation SourceUrlView
{
    UILabel *_textLabel;
    UILabel *_sourceLabel;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    self.alpha = 0.82;
    if (self) {
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(sourceUrlViewTap:)];
        [self addGestureRecognizer:tap];
        
        CGFloat width = [@"原网页阅读" sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11.0]}].width;
        
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(MTScreenW-15-width, 0, width, kSourceUrlViewHeight)];
        textLabel.text = @"原网页阅读";
        textLabel.font = [UIFont systemFontOfSize:11.0];
        [self addSubview:textLabel];
        _textLabel = textLabel;
        
        UILabel *sourceUrl = [[UILabel alloc] init];
        sourceUrl.frame = CGRectMake(15, 0, MTScreenW-30-width, kSourceUrlViewHeight);
        sourceUrl.font = textLabel.font;
        sourceUrl.textAlignment = NSTextAlignmentCenter;
        _sourceLabel = sourceUrl;
        [self addSubview:sourceUrl];
    }
    [self setIsNight:_isNight];
    
    return self;
}

- (void)showWithUrlStr:(NSString *)urlStr {
    
    _sourceLabel.text = urlStr;
}

- (void)sourceUrlViewTap:(UITapGestureRecognizer *)tap {
    
    if ([self.delegate respondsToSelector:@selector(sourceUrlView:sourceUrlBtnClick:)]) {
        [self.delegate sourceUrlView:self sourceUrlBtnClick:nil];
    }
}

-(void)setIsNight:(BOOL)isNight{
    
    _isNight = isNight;
    
    self.backgroundColor =  MTConfigColor(_isNight?@"MTReaderBar_NightSourceBg_Color":@"MTReaderBar_DaySourceBg_Color");
    _sourceLabel.textColor = MTConfigColor(_isNight?@"MTReaderBar_NightNomarlText_Color":@"MTReaderBar_DayNomarlText_Color");
    _textLabel.textColor = _sourceLabel.textColor;
}

@end
